package com.fyy.java8.methodRef;

import java.util.List;
import java.util.function.Supplier;

/**
 * @Author fyy
 * @Description 构造器引用及数组引用
 * @Date 2021/2/25 15:52
 */
public class ConstructorTest {

    /** 构造器引用 */
    public void test1(){
        //正常编写
        Supplier<User> s = new Supplier<User>() {
            @Override
            public User get() {
                return new User();
            }
        };
        //lambda表达式
        Supplier<User> s1 = () -> new User();
        //构造器引用
        Supplier<User> s2 = User :: new;
    }

    /** 数组引用 */
    public static void test2(){
        //正常编写
        Supplier<List<User>> s = new Supplier<List<User>>() {
            @Override
            public List<User> get() {
                return UserData.getUsersData();
            }
        };
        //lambda表达式
        Supplier<List<User>> s1 = () -> UserData.getUsersData();
        System.out.println(s1.get());
        //组引用
        Supplier<List<User>> s2 = UserData :: getUsersData;
        System.out.println(s2.get());
    }

}
